//
//  DSNavigationController.m
//  项目A_百思不得姐
//
//  Created by wudongyang on 16/5/18.
//  Copyright © 2016年 wudongyang. All rights reserved.
//

#import "DSNavigationController.h"

@interface DSNavigationController ()

@end

@implementation DSNavigationController

- (void)viewDidLoad {
    [super viewDidLoad];
    
   
    
    // Do any additional setup after loading the view.
    

    
}
// 可以在这个方法中拦截所有push进来的控制器
-(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
    // 如果push进来的不是第一个控制器
    if (self.childViewControllers.count > 0) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button setTitle:@"返回" forState:UIControlStateNormal];
        [button setImage:[UIImage imageNamed:@"navigationButtonReturn"] forState:UIControlStateNormal];
        [button setImage:[UIImage imageNamed:@"navigationButtonReturnClick"] forState:UIControlStateHighlighted];

        button.frame = CGRectMake(0, 0, 70, 30);
        
        // 让按钮里所有内容左对齐
        button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        // 让按钮里的内容偏移出去
        button.contentEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 0);
        // 让按钮大小跟随内容大小
//        [button sizeToFit];
        // 设置按钮文字颜色
        [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        // 设置按钮选中颜色
        [button setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
        // 设置按钮点击方法
        [button addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
        viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
        // 隐藏tabBar
        viewController.hidesBottomBarWhenPushed = YES;
    }
    // 这句super的push要放在后面, 让viewController可以覆盖上面设置的leftBarButtonItem
    [super pushViewController:viewController animated:animated];
    
}
-(void)back{
    [self popViewControllerAnimated:YES];



}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
